home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / text / blank.c next >
C/C++ Source or Header  |  1993-08-15  |  3KB  |  126 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <dos/dos.h>
  5.  
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8. #include <graphics/text.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/intuition_protos.h>
  12. #include <clib/graphics_protos.h>
  13. #include <clib/dos_protos.h>
  14. #include <clib/diskfont_protos.h>
  15. #include <clib/utility_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <stdio.h>
  19.  
  20. #include "Text.h"
  21. #include "/defs.h"
  22. #include "/utility.h"
  23.  
  24. struct tPrefObject {
  25.     UBYTE text[128];
  26.     UBYTE fName[64];
  27.     UBYTE Speed;
  28.     UBYTE State;
  29.     UBYTE Cycle;
  30.     struct TextAttr Font;
  31. };
  32.  
  33. extern    struct    tPrefObject    nP;
  34. extern        ULONG   Depth, Mode;
  35. extern        UBYTE   *prefData;
  36.  
  37. VOID blank( VOID )
  38. {
  39.     struct    TextFont    *font;
  40.     struct    tPrefObject    *tP;
  41.     struct    Screen        *TextScr;
  42.     UBYTE    vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4,
  43.         3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  44.     UBYTE    scrText[128], c1 = 0, c2 = 14, c3 = 28, *ptr;
  45.     ULONG    x = 2, y, Wid, Hei, len, numc, base, count;
  46.     LONG    dx = 1, dy = 1, delay, cycle = 0;
  47.     FILE    *textFile;
  48.  
  49.     if( TextWnd ) tP = &nP;
  50.     else tP = ( struct tPrefObject * )prefData;
  51.  
  52.     if( tP->State ) {
  53.         if( textFile = fopen( tP->text, "r" )) {
  54.             fscanf( textFile, "%lu", &count );
  55.             numc = RangeRand( count+1 );
  56.             while((( fgetc( textFile ) == '\n' )?++cycle:cycle ) < numc );
  57.             fscanf( textFile, "%s %d ", tP->fName, &delay );
  58.             tP->Font.ta_YSize = (WORD)delay;
  59.             fgets( scrText, 128, textFile );
  60.             for( ptr = scrText; ptr[0]; ++ptr );
  61.             (--ptr)[0] = 0;
  62.             fclose( textFile );
  63.         } else sprintf( scrText, "Could not open: %s", tP->text );
  64.     } else CopyMem( tP->text, scrText, 128 );
  65.  
  66.     tP->Font.ta_Name = tP->fName;
  67.     font = OpenDiskFont( &( tP->Font ));
  68.     base = font->tf_Baseline;
  69.  
  70.     TextScr = OpenScreenTags( 0l, SA_DisplayID, Mode, SA_Depth, 1, SA_Quiet, TRUE, SA_Overscan, OSCAN_STANDARD,
  71.         SA_Font, &( tP->Font ), SA_Behind, TRUE, TAG_DONE );
  72.  
  73.     Wid = TextScr->Width;
  74.     Hei = TextScr->Height;
  75.  
  76.     for( ptr = scrText; ptr[0]; ++ptr );
  77.     numc = ptr-scrText;
  78.     while(( len = TextLength( &(TextScr->RastPort), scrText, numc )) >= Wid-5 ) numc--;
  79.  
  80.     y = RangeRand( Hei - tP->Font.ta_YSize );
  81.  
  82.     SetRGB4( &(TextScr->ViewPort), 0, 0L, 0L, 0L );
  83.     switch( tP->Cycle ) {
  84.     case 0:
  85.         SetRGB4( &(TextScr->ViewPort), 1, vals[c1], vals[c2], vals[c3] );
  86.         break;
  87.     case 1:
  88.         SetRGB4( &(TextScr->ViewPort), 1, RangeRand( 15 ) + 1, RangeRand( 15 ) + 1, RangeRand( 15 ) + 1 );
  89.         break;
  90.     case 2:
  91.         SetRGB4( &(TextScr->ViewPort), 1, 15, 15, 15 );
  92.         break;
  93.     case 3:
  94.         setCopperList( Hei, 1, &( TextScr->ViewPort ));
  95.         break;
  96.     }        
  97.  
  98.     SetAPen( &(TextScr->RastPort), 1 );
  99.     Move( &(TextScr->RastPort), x, y + base );
  100.     Text( &(TextScr->RastPort), scrText, numc );
  101.  
  102.     delay = 51 - tP->Speed;
  103.  
  104.     BlankMousePointer();
  105.     ScreenToFront( TextScr );
  106.  
  107.     while(!( SetSignal( 0L, 0L )&SIGBREAKF_CTRL_C )) {
  108.         WaitTOF();
  109.         if(!( ++count%delay )) {
  110.             if( !tP->Cycle && !(count%(10*delay))) SetRGB4( &(TextScr->ViewPort), 1, vals[c1 = ++c1%42],
  111.                 vals[c2 = ++c2%42], vals[c3 = ++c3%42] );
  112.             ScrollRaster( &(TextScr->RastPort), dx, dy, x-1, y-1, x+1+len, y+1+tP->Font.ta_YSize );
  113.             x -= dx; y -= dy;
  114.             if( x < 2 ) dx = -1;
  115.             else if( x > Wid-len-2 ) dx = 1;
  116.             if( y < 2 ) dy = -1;
  117.             else if( y > Hei-tP->Font.ta_YSize-2 ) dy = 1;
  118.         }
  119.     }
  120.     SetSignal( 0L, SIGBREAKF_CTRL_C );
  121.  
  122.     if( font ) CloseFont( font );
  123.     UnblankMousePointer();
  124.     CloseScreen( TextScr );
  125. }
  126.